package com.darren.euc.dao.impl;


import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.PlaceDao;
import com.darren.euc.entity.City;
import com.darren.euc.entity.Province;


@Repository
public class PlaceDaoImpl extends BaseDaoImpl<Province, Integer> implements PlaceDao {
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Province> getAllProvinces() {
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery(" from Province where enable = true order by provinceId asc ").list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<City> getAllCity() {		
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery("from City where enable = true order by cityId asc").list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<City> getCitiesByProvinceId(Integer provinceId) {
		Session session = sessionFactory.getCurrentSession();	
		return session.createQuery("from City where provinceId = ?").setParameter(0, provinceId).list();
	}

	@Override
	public City getCityById(Integer id) {
		Session session = sessionFactory.getCurrentSession();	
		return (City) session.createQuery("from City where id = ? and enable = true ").setParameter(0, id).uniqueResult();
	}
	
}